Skip to content

feat: add llama-index-tools-commune for email and SMS#20855

Open
shanjairaj7 wants to merge 6 commits intorun-llama:mainfrom
shanjairaj7:feat/commune-tools
Open

feat: add llama-index-tools-commune for email and SMS#20855
shanjairaj7 wants to merge 6 commits intorun-llama:mainfrom
shanjairaj7:feat/commune-tools

Conversation

@shanjairaj7
Copy link

@shanjairaj7 shanjairaj7 commented Mar 3, 2026

Summary

This PR adds a new tool integration: llama-index-tools-commune, which gives LlamaIndex agents a real email inbox and SMS capability via Commune.

What is Commune?

Commune is email and SMS infrastructure built specifically for AI agents. It provides:

  • A real, deliverable inbox that agents can read and write to
  • Outbound email and SMS sending with high deliverability
  • A simple Python SDK (commune-mail on PyPI)
  • Per-message credit billing with no monthly minimums

This is useful for agentic workflows where the agent needs to communicate with humans or other systems through standard channels — customer support triage, automated notifications, multi-agent coordination, and so on.

Real use case: customer support email routing

import os
from llama_index.core.agent import ReActAgent
from llama_index.llms.openai import OpenAI
from llama_index.tools.commune import CommuneToolSpec

tools = CommuneToolSpec(api_key=os.environ["COMMUNE_API_KEY"])

agent = ReActAgent.from_tools(
    tools.to_tool_list(),
    llm=OpenAI(model="gpt-4o"),
    verbose=True,
    system_prompt=(
        "You are a customer support triage agent. Check the inbox for unread "
        "emails, categorize each request (billing, technical, general), and "
        "route them by forwarding to the appropriate team email address with "
        "a brief summary of the issue."
    ),
)

agent.chat("Process any unread support emails in the inbox.")

The agent will call load_inbox(unread_only=True), read each email with get_email, then call send_email to route each one — all without any custom tool wiring.

Spec functions

Function Description
load_inbox Fetch recent emails; supports limit and unread_only filter
search_emails Full-text search across inbox by keyword, sender, or topic
get_email Retrieve the complete body of a specific email by ID
send_email Send an email with to/subject/body and optional from address
send_sms Send an SMS to a phone number in E.164 format
get_credits Check API credit balance; warns when balance is low

Package details

  • PyPI: pip install llama-index-tools-commune (will be published on merge)
  • Upstream SDK: commune-mail on PyPI
  • Python: >=3.9
  • Depends on: llama-index-core>=0.11.0, commune-mail>=0.2.0
  • Author: @shanjai-raj

Files added

llama-index-integrations/tools/llama-index-tools-commune/
├── pyproject.toml
├── README.md
└── llama_index/
    ├── __init__.py
    └── tools/
        ├── __init__.py
        └── commune/
            ├── __init__.py
            └── base.py          ← CommuneToolSpec implementation

Checklist

  • Package follows the existing llama-index integration pattern (BaseToolSpec)
  • All spec_functions have rich docstrings for LLM consumption
  • Error handling returns helpful strings rather than raising exceptions
  • README includes installation, setup, and three worked examples
  • pyproject.toml includes [tool.llamahub] metadata

@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Mar 3, 2026
Copy link
Member

@AstraBert AstraBert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core looks good, but tests are needed before merging

Comment on lines +58 to +64
try:
from commune import Commune # type: ignore[import]
except ImportError as exc:
raise ImportError(
"commune-mail is required. Install it with: "
"pip install commune-mail"
) from exc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a required dependency, no need for lazy importing + error checking, you can import at the top

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants